home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / Arashi 1.1 / Game Source / mtz / mtz src / STFloatingScores.c copy < prev    next >
Encoding:
Text File  |  1993-01-17  |  4.4 KB  |  236 lines  |  [TEXT/KAHL]

  1. /* This file takes care of the floating scores above Fuseballs                     */
  2. /* It basically implememts another set of 7 segment #'s, like VADrawNumber         */
  3. /* but it is compatible with using on the pplaying field, VADrawNumber will     */
  4. /* overdraw the playing field and leave holes when erased. (mz)                    */
  5.  
  6. /* December 22,1992 © Mike Zimmerman */
  7.  
  8.  
  9. #include "VA.h"
  10. #include "Storm.h"
  11. #include <Math.h>
  12.  
  13. #define STARTAGE         40
  14. #define    MAXFLSCORES        20
  15.  
  16. #define METHOD2
  17.  
  18. extern    Player    Hero;
  19.  
  20. typedef struct
  21. {
  22.     int        AGE;
  23.     int        score;
  24.     int        x1;
  25.     int        y1;
  26.     int        scale;
  27. }    FloatingScore;
  28.  
  29. #ifdef METHOD1
  30. char    digits[]={    1+2+4+8+16+32,        /*    0    */
  31.                       2+4,                /*    1    */
  32.                     1  +4+8   +32+64,    /*    2    */
  33.                     1+2+4+8      +64,    /*    3    */
  34.                       2+4  +16   +64,    /*    4    */
  35.                     1+2  +8+16   +64,    /*    5    */
  36.                     1+2  +8+16+32+64,    /*    6    */
  37.                       2+4+8,            /*    7    */
  38.                     1+2+4+8+16+32+64,    /*    8    */
  39.                     1+2+4+8+16   +64};    /*    9    */
  40. #endif
  41.  
  42. int    FSCount;
  43. int FSStart;
  44. FloatingScore    *FLScores;
  45.  
  46. #ifdef METHOD1
  47. void    BottomSeg(x,y)
  48. int    x;
  49. int    y;
  50. {
  51.     VAMoveTo(x + 1,y);
  52.     VASafeLineTo(x + VA.segmscale*3 -1,y);     /* bottom segment     */
  53. }
  54.  
  55. void MiddleSeg(x,y)
  56. int    x;
  57. int    y;
  58. {
  59.     VAMoveTo(x + 1,y-VA.segmscale*2-2)
  60.     VASafeLineTo(x + VA.segmscale*3 -1,y-VA.segmscale*2-2);    /* middle segment    */
  61. }
  62.  
  63. void    TopSeg(x,y)
  64. int    x;
  65. int    y;
  66. {
  67.     VAMoveTo(x + 1,y-VA.segmscale*4-4);
  68.     VASafeLineTo(x + VA.segmscale*3 -1,y-VA.segmscale*4-4);     /* top segment         */
  69.                 
  70. }
  71.  
  72. void    LeftBtSeg(x,y)
  73. int    x;
  74. int    y;
  75. {
  76.     VAMoveTo(x,y-1);
  77.     VASafeLineTo(x,y-VA.segmscale*2-2 + 1);     /* left lower segment     */
  78.                 
  79. }
  80. void    LeftUpSeg(x,y)
  81. int    x;
  82. int    y;
  83. {
  84.     VAMoveTo(x,y-VA.segmscale*2-2-1);
  85.     VASafeLineTo(x,y-VA.segmscale*4-4 + 1);     /* left upper segment     */
  86. }
  87.  
  88. void    RightBtSeg(x,y)
  89. int    x;
  90. int    y;
  91. {
  92.     VAMoveTo(x + VA.segmscale*3,y-1);
  93.     VASafeLineTo(x + VA.segmscale*3,y-VA.segmscale*2-2 + 1);     /* right lower segment     */
  94.                 
  95. }
  96. void    RightUpSeg(x,y)
  97. int    x;
  98. int    y;
  99. {
  100.     VAMoveTo(x + VA.segmscale*3,y-VA.segmscale*2-2-1);
  101.     VASafeLineTo(x + VA.segmscale*3,y-VA.segmscale*4-4 + 1);     /* right upper segment     */
  102. }
  103.  
  104. void    DrawScore(x,y,score)
  105. int    x;
  106. int    y;
  107. int    score;
  108. {
  109.     int        digit;
  110.     int        i;
  111.     int        numlen;
  112.     int        curx;
  113.     int        mask;
  114.     
  115.     
  116.     VA.color=3;                        
  117.     
  118.     VA.segmscale=(int)(Getfontscale()*3/4);
  119.     
  120.     numlen = (int) log10(score);
  121.     for(i=0; i <= numlen; i++)
  122.     {
  123.         curx = x + (VA.segmscale*3+3)*i;
  124.         VAMoveTo(curx,y);
  125.         digit = (int)( score/pow(10,(numlen-i)) );
  126.         score -= digit*pow(10,(numlen-i));
  127.         mask = digits[digit];
  128.         if (mask & 1)
  129.             BottomSeg(curx,y);     
  130.         if (mask & 2)
  131.             RightBtSeg(curx,y);
  132.         if (mask & 4)
  133.             RightUpSeg(curx,y);
  134.         if (mask & 8)
  135.             TopSeg(curx,y);
  136.         if (mask & 16)
  137.             LeftUpSeg(curx,y);
  138.         if (mask & 32)    
  139.             LeftBtSeg(curx,y);
  140.         if (mask & 64)
  141.             MiddleSeg(curx,y);
  142.     }
  143. }
  144.  
  145. void UpdateFloatingScores()
  146. {
  147.     int    i,j;
  148.  
  149.     for(i = FSStart;i < ((FSCount+FSStart)%MAXFLSCORES) ; i++)
  150.     {
  151.         j=i%MAXFLSCORES;
  152.         FLScores[j].AGE -= 1;
  153.         if (FLScores[j].AGE == 0 || Hero.state == HeroFlying) 
  154.         /* Score expired, so remove it */
  155.         {
  156.             FLScores[j].AGE = 0;
  157.             FSCount--;
  158.             FSStart++;
  159.         }
  160.          else DrawScore(FLScores[j].x1,FLScores[j].y1,FLScores[j].score); 
  161.     }
  162. }    
  163. #endif
  164.  
  165.  
  166. #ifdef METHOD2
  167. void    DrawScore(x,y,score,scale)
  168. int    x;
  169. int    y;
  170. int    score;
  171. int    scale;
  172. {
  173.     int        numlen;
  174.     
  175.     VA.color=BG1;                        
  176.     VA.segmscale=scale;
  177.     VADrawNumber(score,x,y);
  178. }
  179.  
  180. void UpdateFloatingScores()
  181. {
  182.     int    i,j;
  183.  
  184.     for(i = FSStart;i < ((FSCount+FSStart)%MAXFLSCORES) ; i++)
  185.     {
  186.         j=i%MAXFLSCORES;
  187.         FLScores[j].AGE -= 1;
  188.         if (FLScores[j].AGE == 0 || Hero.state == HeroFlying) 
  189.         /* Score expired, so remove it */
  190.         {
  191.             VA.color=-1;                        
  192.             VA.segmscale=FLScores[j].scale;
  193.             VADrawNumber(FLScores[j].score,FLScores[j].x1,FLScores[j].y1);
  194.             FLScores[j].AGE = 0;
  195.             FSCount--;
  196.             FSStart++;
  197.             VA.color=0;
  198.             if (FSCount == 0)
  199.                 RedrawField();
  200.         }
  201.     }
  202. }
  203. #endif
  204.  
  205. void    AddFLScore(x,y,fscore)  /* mz */
  206. int    x;
  207. int    y;
  208. int    fscore;
  209. {
  210.     FLScores[(FSCount+FSStart)%MAXFLSCORES].scale = (int)(Getfontscale());
  211.     DrawScore(x,y,fscore,FLScores[(FSCount+FSStart)%MAXFLSCORES].scale);
  212.     FLScores[(FSCount+FSStart)%MAXFLSCORES].AGE=STARTAGE;
  213.     FLScores[(FSCount+FSStart)%MAXFLSCORES].score=fscore;
  214.     FLScores[(FSCount+FSStart)%MAXFLSCORES].x1=x;
  215.     FLScores[(FSCount+FSStart)%MAXFLSCORES].y1=y;
  216.     FLScores[(FSCount+FSStart)%MAXFLSCORES].scale = (int)(Getfontscale());
  217.     FSCount++;
  218. }
  219.  
  220. void    AllocFloatingScores()
  221. {
  222.     FLScores=(FloatingScore *)NewPtr(sizeof(FloatingScore) * MAXFLSCORES);
  223.     FSCount=0;
  224. }
  225.  
  226. void    InitFloatingScores()
  227. {
  228.     register    int        i;
  229.     
  230.     for(i=0;i<MAXFLSCORES;i++)
  231.     {    FLScores[i].AGE=0;
  232.     }
  233.     FSCount=0;
  234.     FSStart=0;
  235. }
  236.